﻿package net.wangit;

import net.wangit.context.ActionContext;
import net.wangit.jdbc.DB;
import net.wangit.jdbc.Type;
import net.wangit.user.UserFactory;

/**
 * 用户应用接口。
 * 
 * @author watson Feb 24, 2010
 */
public class UserSupport {

	private static final String UPDATE_GROUP = "update AUSERGROUP set userid=? where userid=?";
	private static final String UPDATE_ROLE = "update AUSERROLE set userid=? where userid=?";
	private static final String DELETE_GROUP = "delete from AUSERGROUP where userid=?";
	private static final String DELETE_ROLE = "delete from AUSERROLE where userid=?";

	// 更新用户。
	public static void updateUser(DB db, String newUserId, String oldUserId)
			throws Exception {
		String values[] = { newUserId, oldUserId };
		int types[] = { Type.VARCHAR, Type.VARCHAR };
		db.execute(UserSupport.UPDATE_GROUP, values, types);
		db.execute(UserSupport.UPDATE_ROLE, values, types);
	}

	// 删除用户。
	public static void deleteUser(DB db, String userId) throws Exception {
		db.execute(UserSupport.DELETE_GROUP, userId, Type.VARCHAR);
		db.execute(UserSupport.DELETE_ROLE, userId, Type.VARCHAR);
	}

	// 用户登录。
	public static boolean login(ActionContext ac, String userId, String password)
			throws Exception {
		return UserFactory.getUser(ac, userId, password) != null;
	}

	private UserSupport() {
	}
}
